$(function () {
    // 初始化内容
    pagehtml(0);
    $("#bakMenu").attr("class","active");
    $("#breadcrumb").html("快照列表");
    $("#myAlert").css('display', 'none');
    $("#btnSearch").click(function () {
        pagehtml(0);
    });
    $("#delBtn").click(function () {
        Ewin.confirm({message: "确认要删除选择的数据吗？"}).on(function (e) {
            if (!e) {
                return;
            }
            var delDate = $("#delDate").val();
            $.post("/back/monitor/bakDel", {delDate: delDate}, function (data) {
                if (data.status == 200) {
                    $("#myAlert").css('display', 'block');
                    $("#alertMsg").html("数据删除成功");
                } else {
                    $("#myAlert").css('display', 'block');
                    $("#alertMsg").html("数据删除失败");
                }
            });
        });
    });
});

function pagehtml(pageNum) {
    if (pageNum == 0) {
        pageNum = 1;
    } else {
        pageNum = pageNum;
    }
    var bizId = $("#bizId").val();
    var account = $("#account").val();
    var accountType = $("#accountType").val();
    var type = $("#type").val();
    var basePath = getContextPath();
    $.ajax({
        url: basePath + "/back/monitor/bakList",
        type: "post",
        dataType: "json",
        data: {
            pageNum: pageNum,
            pageSize: 20,
            account: account,
            accountType: accountType,
            type: type,
            bizId: bizId
        },
        success: function (data) {
            var options = {
                bootstrapMajorVersion: 3,//bootstrap版本
                alignment: "center",//居中显示
                currentPage: data.pageNum,//当前页数
                totalPages: data.totalPages,//总页数 注意不是总条数
                pageUrl: function (type, page, current) {
                    if (page == current) {
                        return "javascript:void(0)";
                    } else {
                        return "javascript:pagehtml(" + page + ")";
                    }
                }
            };
            var html = "";
            $.each(data.list, function (i, obj) {
                html += "<tr>" +
                    "<td>" + obj.id + "</td>" +
                    "<td>" + obj.bizId + "</td>"+
                    "<td>" + obj.account + "</td>";
                if (obj.accountType == '010') {
                    html += "<td><a href='#' class='btn btn-success'>低频</a></td>";
                } else if (obj.accountType == '020') {
                    html += "<td><a href='#' class='btn btn-info'>活跃</a></td>";
                } else if (obj.accountType == '030') {
                    html += "<td><a href='#' class='btn btn-warning'>高频</a></td>";
                } else if (obj.accountType == '040') {
                    html += "<td><a href='#' class='btn btn-danger'>T-1</a></td>";
                }  else if (obj.accountType == '050') {
                    html += "<td><a href='#' class='btn btn-success'>40/次</a></td>";
                } else if (obj.accountType == '060') {
                    html += "<td><a href='#' class='btn btn-success'>20/次</a></td>";
                }else {
                    html += "<td><a href='#' class='btn btn-info'>其他</a></td>";
                }
                html +="<td>" + obj.reqTime + "</td>" +
                    "<td>" + obj.retTime + "</td>" +
                    "<td>" + obj.bankName + "</td>" +
                    "<td>" + obj.ifCode + "</td>";
                if (obj.type == '010') {
                    html += "<td><a href='#' class='btn btn-success'>当日</a></td>";
                } else if (obj.type == '020') {
                    html += "<td><a href='#' class='btn btn-info'>历史</a></td>";
                }
                if (obj.retStatus == '010') {
                    html += "<td><a href='#' class='btn btn-primary'>初始化</a></td>";
                } else if (obj.retStatus == '020') {
                    html += "<td><a href='#' class='btn btn-success'>有效</a></td>";
                } else if (obj.retStatus == '030') {
                    html += "<td><a href='#' class='btn btn-danger'>失败</a></td>";
                } else if (obj.retStatus == '040') {
                    html += "<td><a href='#' class='btn btn-warning'>无效</a></td>";
                }
                html += "<td>" + obj.retMsg + "</td>" +
                    "<td>" + obj.createTime + "</td>" +
                    "<td>" + obj.updateTime + "</td>" +
                    "</tr>";

            });
            $("#content").empty();
            $("#content").append(html);
            $('#data-pagination').bootstrapPaginator(options);
        },
        error: function (error) {
            alert("error");
        }
    });
}
